
const express = require("express");
// const knex = require("../../db/config");
const bodyParser = require("body-parser");
const Project = express.Router();
// import { TuyaContext } from '@tuya/tuya-connector-nodejs'; // 上次忘记把这个开起来 白下载了tuya npm 包
const { TuyaContext }  = require("@tuya/tuya-connector-nodejs")
Project.use(bodyParser.json());
Project.use(express.urlencoded({ extended: true }));
Project.use(express.static(__dirname + "/www"));
Project.use(express.json());


const context = new TuyaContext({
      baseUrl: 'https://openapi.tuyacn.com',
    });
/**
 * 登录
 * @route POST /LoginSync
 * @group 项目模块 - Operation about user
 * @returns {object} 200 - An array of user info
 * @returns {Error}  default - Unexpected error
 */
Project.get("/ProjectList", async (req, res) => {
      const tenantId = req.tenantId;
      console.log("租户ID",tenantId)
});


// 查询空间下项目列表

Project.get("/getSpaceList", async (req,res) => {
  const  { device_ids} = req.query
  const result = await context.request({
    path: `/v2.0/cloud/thing/batch?device_ids=${device_ids}`,
    method: 'GET',
  });
  if(result.success){
      res.send(result)
  }
})

// 使用module.exprots导出

module.exports = Project;